package com.sh.stream流;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class Stream练习 {
    public static void main(String[] args) {
//        ArrayList<Integer> integerArrayList = new ArrayList<>();
//        Collections.addAll(integerArrayList, 1, 2, 3, 4, 5, 6, 7, 8, 9);
//        Set<Integer> collect = integerArrayList.stream().filter(num -> num % 2 == 0).collect(Collectors.toSet());
//        System.out.println(collect);
//
//
//        ArrayList<String> nameList = new ArrayList<>();
//        Collections.addAll(nameList, "zhangsan, 23", "lisi, 24", "wangwu, 25");
//        Map<String, String> collect1 = nameList.stream()
//                .filter(one -> Integer.valueOf(one.split(",")[1].trim()) >= 24)
//                .collect(Collectors.toMap(one -> one.split(",")[0],
//                        one -> one.split(",")[1]));
//        System.out.println(collect1);


        List<String> maleActors = Arrays.asList("胡歌，33", "李现，32", "彭于晏，36", "王凯，34", "张译，40","郭富城，22", "吴彦祖，44");

        List<String> femaleActors = Arrays.asList("杨幂，33", "赵丽颖，32", "迪丽热巴，30", "刘诗诗，34", "杨嫣，35");

        List<String> collect1 = maleActors.stream()
                .filter(name -> name.split("，")[0].length() >= 3)
                .limit(2).collect(Collectors.toList());
        System.out.println(collect1);


        List<String> collect2 = femaleActors.stream().filter(name -> name.startsWith("杨")).skip(1).collect(Collectors.toList());
        System.out.println(collect2);

        List<String> collect = Stream.concat(collect1.stream(), collect2.stream()).collect(Collectors.toList());
        System.out.println(collect);

        List<Actor> collect3 = Stream.concat(collect1.stream(), collect2.stream()).map(new Function<String, Actor>() {
            @Override
            public Actor apply(String s) {
                String[] split = s.split("，");
                Actor actor = new Actor(split[0], split[1]);
                return actor;
            }
        }).collect(Collectors.toList());
        collect3.forEach(System.out::println);



        List<Actor> collect4 = Stream
                .concat(collect1.stream(), collect2.stream())
                .map(one->  new Actor(one.split("，")[0],one.split("，")[1] ))
                .collect(Collectors.toList());
        collect4.forEach(System.out::println);

    }
}

